package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class JDBCDemo5 {
    public static void main(String[] args) {
        try (Connection connection = DBUtil.getConnection()){
            Statement statement = connection.createStatement();
            String sql = "SELECT COUNT(*) count FROM  class c  JOIN student t ON c.id = t.class_id AND c.name= '1年级1班'";
            ResultSet rs=statement.executeQuery(sql);
            if(rs.next()){//因为统计的结果集只有一条记录，因此可以使用if
               int count = rs.getInt("count");
                System.out.println(count);
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }

    }
}
